package com.nullam.lorem.contactsync.adaptor;

import java.util.ArrayList;

import com.nullam.lorem.contactsync.R;
import com.nullam.lorem.contactsync.data.ItemNavigation;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

public class NavigationAdapter extends BaseAdapter {
	private Context context;
	private ArrayList<ItemNavigation> arr;

	public NavigationAdapter(Context mContext, ArrayList arr){
		super();
		context = mContext;
		this.arr = arr;
	}

	@Override
	public int getCount() {
		// TODO Auto-generated method stub
		int count = 0;
		if (arr != null) {
			count = arr.size();
		}
		return count;
	}

	@Override
	public Object getItem(int arg0) {
		// TODO Auto-generated method stub
		return arr.get(arg0);
	}

	@Override
	public long getItemId(int arg0) {
		// TODO Auto-generated method stub
		return 0;
	}

	@Override
	public View getView(int pos, View convertView, ViewGroup parent) {
		// TODO Auto-generated method stub
		ViewHolder holder;
		if(convertView == null){
			convertView = LayoutInflater.from(context).inflate(R.layout.item_navigation, parent, false);
			holder = new ViewHolder(); //ViewHolder tu tao ben duoi
			holder.itemIcon = (ImageView) convertView.findViewById(R.id.itemIcon);//.....
			holder.itemName = (TextView) convertView.findViewById(R.id.itemName);
			convertView.setTag(holder);
		}
		else
		{
			holder = (ViewHolder) convertView.getTag();
		}

		ItemNavigation itemNavi = arr.get(pos);
		if(itemNavi != null){
			holder.itemIcon.setImageResource(itemNavi.getItemIcon());
			holder.itemName.setText(itemNavi.getItemName());
		}
		//		holder.itemIcon.setOnClickListener(new OnClickListener() {
		//			
		//			@Override
		//			public void onClick(View v) {
		//				// TODO Auto-generated method stub
		//				
		//			}
		//		});
		return convertView;
	}
	class ViewHolder{
		ImageView itemIcon;
		TextView itemName;
	}
}
